package com.jiajun.ct.analysis.reducer;

import com.jiajun.ct.analysis.kv.AnalysisKey;
import com.jiajun.ct.analysis.kv.AnalysisValue;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * 分析数据的reducer
 */
public class AnalysisBeanReducer extends Reducer<AnalysisKey,Text,AnalysisKey, AnalysisValue> {

    @Override
    protected void reduce(AnalysisKey key, Iterable<Text> values, Context context) throws IOException, InterruptedException {

        //通话总次数和通话总时长，是对于相同key来说的，而相同的key在map端有三个指标
        int sumCall = 0;
        int sumDuration = 0;

        for (Text value : values) {
            int duration = Integer.parseInt(value.toString());

            sumDuration += duration;

            sumCall++;
        }


        context.write(key,new AnalysisValue(""+sumCall,""+sumDuration));
    }
}
